package HomeWorlk;

import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

/*2. 分析以下需求，并用代码实现：
        (1)统计每个单词出现的次数
        (2)有如下字符串"If you want to change your fate I think you must" +
        " come to the dark horse to learn java"(用空格间隔)
        (3)打印格式：
        to=3
        think=1
        you=2
//........*/
public class test2 {
    public static void main(String[] args) {
        String s = "If you want to change your fate I think you must come to the dark horse to learn java";
       /* StringTokenizer s1 = new StringTokenizer(s," ");
        while (s1.hasMoreElements()){
            System.out.println(s1.nextElement());
        }*/
        String s1[] = s.split(" ");
        HashMap<String, Integer> hm = new HashMap<>();
        for (String s2 : s1) {
            System.out.println();
            Integer num = hm.get(s2);
            if (num == null) {
                hm.put(s2, 1);
            }else {
                    hm.put(s2,++num);
            }
        }
        System.out.println(hm);
    }
}
